package com.longtengyuyun.reentrantLock;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @author ZhaoYunLong
 * @date 2022/3/15
 * @description
 */
public class ReentrantLockTest01 {

    public static void main(String[] args) {

        // 是否公平强锁
        Lock lock = new ReentrantLock(true);

//        lock.tryLock();
//        lock.lock();
//        lock.unlock();

        Thread thread = new Thread(() -> {
            System.out.println("this is " + Thread.currentThread().getName());
        });


        Thread thread1 = new Thread(() -> {
            for (int i = 0; i < 10; i++) {
                lock.lock();
                try {
                    boolean update = lock.tryLock();

                }catch (Exception e) {
                    e.printStackTrace();
                } finally {
                    lock.unlock();
                }
            }
        });
        thread.start();
        thread1.start();

    }





}
